package com.hzhr.iot.toll.dao.helper;

import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.toll.dao.GasUserDao;
import com.hzhr.iot.toll.entity.GasUserEntity;
import com.hzhr.iot.toll.queryModel.custom.GasUserCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class GasUserDaoHelper {
    @Autowired
    GasUserDao gasUserDao;

    public GasUserEntity getByIdAndResourceCode(int id, String resourceCode) {
        GasUserCustomQueryModel queryModel = new GasUserCustomQueryModel();
        queryModel.setEqual_id(id);
        queryModel.setLike_resourceCode(resourceCode + "%");
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        queryModel.setShow(true);
        GasUserEntity gasUserEntity = gasUserDao.selectEntity(queryModel);
        return gasUserEntity;
    }

    public GasUserEntity getByCodeAndResourceCode(String code, String resourceCode) {
        GasUserCustomQueryModel queryModel = new GasUserCustomQueryModel();
        queryModel.setEqual_code(code);
        queryModel.setLike_resourceCode(resourceCode + "%");
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        queryModel.setShow(true);
        GasUserEntity gasUserEntity = gasUserDao.selectEntity(queryModel);
        return gasUserEntity;
    }

    public int getCountByCodeAndCompanyId(String code, int companyId) {
        GasUserCustomQueryModel queryModel = new GasUserCustomQueryModel();
        queryModel.setEqual_code(code);
        queryModel.setEqual_companyId(companyId);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        int count = gasUserDao.selectCount(queryModel);
        return count;
    }

    public int deleteByIdAndResourceCode(int id, String resourceCode, int loginUserId) {
        GasUserCustomQueryModel queryModel = new GasUserCustomQueryModel();

        queryModel.setEqual_id(id);
        queryModel.setLike_resourceCode(resourceCode);

        queryModel.setSet_isValid(CommonOptions.YES_NO.NO);
        queryModel.setSet_updateTime(new Date());
        queryModel.setSet_updateUserId(loginUserId);

        int changeCount = gasUserDao.updateProps(queryModel);

        return changeCount;
    }
}
